home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / GAPLib.lha / GAPLib / doc / text / GAP.doc next >
Encoding:
Text File  |  1999-05-25  |  21.9 KB  |  786 lines

  1. TABLE OF CONTENTS
  2.  
  3. GAP.lib/--background--
  4. GAP.lib/--data items--
  5. GAP.lib/CreatePopulation
  6. GAP.lib/Crossover
  7. GAP.lib/DeletePopulation
  8. GAP.lib/EnterGAP
  9. GAP.lib/Evolve
  10. GAP.lib/Flip
  11. GAP.lib/GaussRand
  12. GAP.lib/HammingDist
  13. GAP.lib/InitRand
  14. GAP.lib/InRand
  15. GAP.lib/IRange
  16. GAP.lib/PopMember
  17. GAP.lib/Rnd
  18. GAP.lib/Testbit
  19. GAP.lib/TossRand
  20.  
  21.  
  22. GAP.lib/--background--                                   GAP.lib/--background--
  23.  
  24.    PURPOSE
  25.     The Genetic Algorithm Programming Library (GAP-Lib) is intended to
  26.     make it easier to implement genetic algorithms for any purpose. The
  27.     library itself implements most of the framework needed to handle one
  28.     or several populations thus leaving the programmer free to concentrate
  29.     on the purpose of her program.
  30.     Some work will still be needed, specifically setting up a genotype,
  31.     creating a fitness function and in some cases functions for
  32.     initializing, mutating, crossing and deleting individuals.
  33.  
  34.    OVERVIEW
  35.     GAP-Lib: A Genetic Algorithm Programming Library.
  36.  
  37.     A library for programming with genetic algorithms. The library features
  38.     a simple yet flexible interface coupled with sensible default values
  39.     and quite powerful built-in functionality to provide for both high and
  40.     low-level programming.
  41.  
  42.     The GAP-Lib is primarily bit-oriented and this is reflected in the
  43.     existing default-functions for crossover and  mutation. It is however
  44.     possible to use almost any representation as long as the library
  45.     itself only sees fixed-length individuals (Variable length individuals
  46.     are possible though).
  47.  
  48.     A typical program using the GAP-Lib will begin by initializing the
  49.     GAP environment by calling EnterGAP() then create a population using
  50.     CreatePopulation() followed by some number of calls to Evolve() and
  51.     finally ending with calling DeletePopulation().
  52.  
  53.     The current version as of 24-May-1999 is 0.82
  54.     (Version 0, Revision 82).
  55.  
  56.     Current limitations include:
  57.  
  58.     · Not thread-safe (And not dynamically linked).
  59.     · Need to implement variable-length individuals manually.
  60.     · No special support for geographical environments.
  61.     · No special support for parallell implementations.
  62.  
  63.  
  64. GAP.lib/--data items--                                   GAP.lib/--data items--
  65.  
  66.    STRUCTURES
  67.     GAP-Lib has three primary structures to keep track of data. One is the
  68.     user-defined structure which describes an individual and though this
  69.     structure is not always nessecary, it is highly recommended that you
  70.     have one since it will help others to read your code.
  71.  
  72.     The other structure is the population structure which in turn includes
  73.     a statistics structure. A member-by-member explanation of these
  74.     structures follow here:
  75.  
  76.     struct Population {
  77.        long   NumPolys;
  78.        long   Generation;
  79.        long   Flags;
  80.        struct Popstat Stat;
  81.        long   Bytes;
  82.        void  *Polys;
  83.        void  *Magic;
  84.     };
  85.  
  86.     NumPolys - This is the number of individuals in the population.
  87.     Generation - This is how many times a generation shift has taken place.
  88.     Flags - Internal status, do not touch.
  89.     Stat - This is the statistics structure, see below.
  90.     Bytes - Bytes per individual.
  91.     Polys - This is for the internal list of individuals, do not touch.
  92.     Magic - This is also internal, do not touch.
  93.  
  94.     struct Popstat {
  95.        double  AverageFitness;
  96.        double  MedianFitness;
  97.        double  TypeFitness;
  98.        long    TypeCount;
  99.        double  StdDeviation;
  100.        double  MaxFitness;
  101.        double  MinFitness;
  102.        void   *Max;
  103.        long    Generation;
  104.     };
  105.  
  106.     AverageFitness - The average fitness of the population.
  107.     MedianFitness - The median fitness of the population.
  108.     TypeFitness - The type (most common) fitness value.
  109.     TypeCount - The number of individuals with the type fitness.
  110.     StdDeviation - The standard deviation of the fitness values.
  111.     MaxFitness - The fitness value of the fittest individual.
  112.     MinFitness - The fitness value of the least fit individual.
  113.     Max - A pointer to the fittest individual after the last call to
  114.           Evolve().
  115.     Generation - The generation for which these statistics are valid.
  116.  
  117.     The Popstat structure is read-only and it is important to remember
  118.     that even if you copy the structure the Max pointer will become
  119.     invalid the next time Evolve() is called.
  120.  
  121.    TAGLISTS
  122.     A taglist is a list of pairs, the first member of the pair is the
  123.     tag and determines what type of data the second member is. A typical
  124.     member of a taglist could look like this:
  125.  
  126.     {EVL_Elite,5}
  127.      ^         ^
  128.      |       |-> The data.
  129.      |-> The type of data.
  130.  
  131.     A complete taglist could look like this:
  132.  
  133.     struct TagItem MyTaglist[]={
  134.        {EVL_Evaluator, fitfunc}, /* Fitness function */
  135.        {EVL_Elite,     5}, /* No. of elite individuals */
  136.        {TAG_DONE,      0}  /* End-Tag */
  137.     };
  138.  
  139.     The End-Tag, TAG_DONE, is a special tag common to all taglists. There
  140.     are currently four such tags defined:
  141.  
  142.     TAG_DONE    - Marks the end of a taglist.
  143.     TAG_END        - Equivalent to TAG_DONE.
  144.     TAG_IGNORE    - This tag is ignored.
  145.     TAG_MORE    - ti_Data is a pointer to a taglist with more tags,
  146.               processing of the current taglist will be terminated.
  147.  
  148.     As some of you might be a bit lazy ;-), there is also an alternative
  149.     way of specifying taglists. At least in GAP-Lib there is. As an example
  150.     we have the function Evolve() which also has and interface named
  151.     EvolveT(), EvolveT() takes a variable number of arguments, the last
  152.     of which make up the taglist. To use the above taglist with EvolveT()
  153.     one would write:
  154.  
  155.     EvolveT(Pop,EVL_Evaluator,fitfunc,EVL_Elite,5,TAG_DONE);
  156.         ^
  157.         |->This is not part of the taglist.
  158.  
  159.    PRIMITIVE TYPES
  160.     GAP-Lib defines one primitive data type; IPTR. The IPTR is a type
  161.     large enough to hold both an integer and a pointer, it is used for
  162.     the data-part of a tagitem. IPTR can be considered equivalent to
  163.     intptr_t as defined in the C9X ISO C-Language standard-to-be.
  164.  
  165.  
  166. GAP.lib/CreatePopulation                               GAP.lib/CreatePopulation
  167.  
  168.    NAME
  169.     CreatePopulation -- Allocates and initializes a population.
  170.     CreatePopulationT -- Varargs interface to CreatePopulation.
  171.  
  172.    SYNOPSIS
  173.     struct Population *CreatePopulation(long int,long int,struct TagItem *)
  174.     struct Population *CreatePopulationT(long int,long int,...);
  175.  
  176.     Pop = CreatePopulation(Num,PSize,TagList);
  177.     Pop = CreatePopulationT(Num,PSize,...);
  178.  
  179.    FUNCTION
  180.     This function will allocate and initialize a population. If no
  181.     initialization function is given, CreatePopulation() will simply
  182.     randomize all bits in the created individuals. There is also a
  183.     predefined initialization function which initializes every individual
  184.     to a string of zero bits.
  185.  
  186.    INPUTS
  187.     Num     - Number of individuals to be created in this population.
  188.     PSize     - The byte-size of the individuals in this population.
  189.     TagList  - A pointer to a taglist.
  190.  
  191.    TAGS
  192.     POP_Init (void (*)(void *)) - A pointer to a function or one of the
  193.          values RAND_INIT or ZERO_INIT. Currently NULL is equivalent to
  194.          ZERO_INIT. A function to initialize an individual should take a
  195.          pointer to an individual and return nothing (void).
  196.  
  197.     POP_Destruct (void (*)(void *)) - A pointer to a function to be called
  198.          when deleting an individual. If you are allocating resources with
  199.          a custom initialization function, then you should supply this
  200.          tag. The function should take a pointer to an individual and
  201.          return nothing (void).
  202.  
  203.     POP_Cache (BOOL) - Set this to false if you are modifying the
  204.          individuals between calls to Evolve() or if you really need to
  205.          save memory. Default is TRUE which enables some caching of data.
  206.  
  207.    RESULT
  208.     Pop     - An initialized population structure or NULL if something
  209.            failed.
  210.  
  211.    NOTE
  212.     CreatePopulation() could fail if EnterGAP() has not been called
  213.     previously (Currently not).
  214.  
  215.    BUGS
  216.     None known.
  217.  
  218.    SEE ALSO
  219.     EnterGAP(), DeletePopulation()
  220.  
  221.  
  222. GAP.lib/Crossover                                             GAP.lib/Crossover
  223.  
  224.    NAME
  225.     Crossover -- Perform crossover on two bitstrings.
  226.  
  227.    SYNOPSIS
  228.     void Crossover(void *,void *,int,int);
  229.  
  230.     Crossover(void *Ind1,void *Ind2,int At,int Size);
  231.  
  232.    FUNCTION
  233.     Performs one-point crossover of two bitstrings. The bitstrings must
  234.     have the same length.
  235.  
  236.    INPUTS
  237.     Ind1    - Pointer to the first bitstring (Individual).
  238.     Ind2    - Pointer to the second bitstring (Individual).
  239.     At    - Bit to perform crossover at.
  240.     Size    - Size of bitstring in bytes. (OBS!: _BYTES_!!)
  241.  
  242.    RESULT
  243.     None.
  244.  
  245.    NOTE
  246.     Note well that all bitstrings must consist of a whole number of bytes.
  247.     This is for reasons of simplicity and efficiency.
  248.  
  249.    BUGS
  250.     None known.
  251.  
  252.    SEE ALSO
  253.     Flip
  254.  
  255.  
  256. GAP.lib/DeletePopulation                               GAP.lib/DeletePopulation
  257.  
  258.    NAME
  259.     DeletePopulation -- Delete a previously allocated population.
  260.  
  261.    SYNOPSIS
  262.     void DeletePopulation(struct Population *);
  263.  
  264.     DeletePopulation(Pop);
  265.  
  266.    FUNCTION
  267.     Deletes a previously allocated population and frees all resources
  268.     associated with it. If no custom deallocation function was given only
  269.     the resources allocated by CreatePopulation() will be freed (If 
  270.     CreatePopulation() was called without a custom initialization function,
  271.     this is probably what you want).
  272.  
  273.    INPUTS
  274.     Pop    - Pointer to the population to be deleted.
  275.  
  276.    RESULT
  277.     None.
  278.  
  279.    BUGS
  280.     None known.
  281.  
  282.    SEE ALSO
  283.     CreatePopulation()
  284.  
  285.  
  286. GAP.lib/EnterGAP                                               GAP.lib/EnterGAP
  287.  
  288.    NAME
  289.     EnterGAP -- Initialize GAP environment.
  290.  
  291.    SYNOPSIS
  292.     void EnterGAP(int Level);
  293.  
  294.     EnterGAP(Level);
  295.  
  296.    FUNCTION
  297.     Initializes the GAP environment.
  298.  
  299.    INPUTS
  300.     Level    - Level of verbosity at startup, supported values range from
  301.           0 to 2 with 0=Quiet, 1=Normal, 2=Verbose.
  302.  
  303.    RESULT
  304.     0 for failure, non-zero for success.
  305.  
  306.    EXAMPLE
  307.     int main(void)
  308.     {
  309.         /* Do some stuff here */
  310.     ...
  311.     if(EnterGAP(1)) {
  312.     ...
  313.     ...    /* Do everything here. */
  314.     ...
  315.     } else {
  316.        fprintf(stderr,"Initialization failed.\n");
  317.     }
  318.  
  319.     return(0); /* Finished, exit. */
  320.     }
  321.  
  322.    BUGS
  323.     None known.
  324.  
  325.    SEE ALSO
  326.  
  327.  
  328.  
  329. GAP.lib/Evolve                                                   GAP.lib/Evolve
  330.  
  331.    NAME
  332.     Evolve -- Performs generation shift on a population.
  333.     EvolveT -- Varargs interface to Evolve().
  334.  
  335.    SYNOPSIS
  336.     struct Population *Evolve(struct Population *,struct TagItem *);
  337.     struct Population *EvolveT(struct Population *,Tag,...);
  338.  
  339.     Pop = Evolve(Pop,TagList);
  340.     Pop = EvolveT(Pop,Tag0Type,...);
  341.  
  342.    FUNCTION
  343.     This is the big one. Evolve performs a generation shift, taking
  344.     a population and returning a new one.
  345.  
  346.    INPUTS
  347.     Pop    - Pointer to an initialized population structure.
  348.     TagList - Pointer to a taglist.
  349.  
  350.    TAGS
  351.     EVL_Evaluator (double (*)(void *)) - Pointer to a function taking
  352.          a pointer to an individual and returning its fitness value
  353.          as a double. Note well that this tag is _required_.
  354.          Also read the NOTE label further down.
  355.  
  356.     EVL_Mutator (void (*)(void *,int)) - Pointer to a mutator function
  357.          taking a pointer to an individual and its size. This function
  358.          should also decide if a mutation is to take place as it will be
  359.          called exactly once for every individual in the population. NULL
  360.          is a permitted value for this tag meaning that no mutation will
  361.          take place. The default is to use a built-in function designed to
  362.          mutate bitstrings.
  363.  
  364.     EVL_Crosser (void (*)(void *,void *,int)) - Pointer to a function which
  365.          performs crossover on two individuals. It should take two pointers
  366.          to individuals and their size and return nothing (void).
  367.          It will be called exactly once for every individual generated by
  368.          crossover. NULL is not a permitted value for this tag. The default
  369.          is to use a built-in function designed to perform crossover on two
  370.          bitstrings.
  371.  
  372.     EVL_Thermostat (double (*)(long,long)) - Pointer to a heat-regulating
  373.          function for Boltzmann selection (TEMPERATURE). The default
  374.          function is PopSize*(2.722-pow(1.0+1.0/Generation,Generation))
  375.          but this might change in later versions. The function takes
  376.          the size of the population as first argument and the generation
  377.          as second.
  378.  
  379.     EVL_Elite (int) - Sets the number of top individuals to copy from one
  380.          generation to the next without crossover (with the risk for
  381.          mutation though). Setting this value high will result in a
  382.          steady-state type of GA. The default value is 0.
  383.          Note!: Setting the Crowding flag currently alters the semantics of
  384.          this tag! If Crowding is in effect the Elite number is the number
  385.          of individuals not to generate. That is, in a population of
  386.          eg. 20 individuals an Elite value of 15 would mean generate
  387.          5 new individuals.
  388.  
  389.     EVL_Flags (unsigned long int) - Bulk initialization of flag tags
  390.          available flags are:
  391.  
  392.         FLG_InitDumped - Same as EVL_InitDumped
  393.         FLG_EraseBest  - Same as EVL_EraseBest
  394.         FLG_Crowding   - Same as EVL_Crowding
  395.         FLG_Statistics - Same as EVL_Statistics
  396.  
  397.          Example usage:  {EVL_Flags,FLG_Crowding|FLG_Statistics}
  398.          **NOTE** If using EVL_Flags, you must explicitly set
  399.          FLG_Statistics to generate statistics.
  400.  
  401.     EVL_Dump (int) - Sets the number of bottom (worst) individuals to dump
  402.          by replacing them with copies of the top (best) individuals.
  403.          Default is 0.
  404.  
  405.     EVL_Select (int) - Sets the select method used to determine parents
  406.          when generating new individuals. Available methods are:
  407.     
  408.         DRANDOM        :    Double-random selection. A random individual
  409.                 and one of those fitter than the first one
  410.                 selected are chosen. (Default)
  411.  
  412.         FITPROP        :    Fitness proportionate selection.
  413.  
  414.         SIGMA        :    Sigma scaled fitness proportionate selection.
  415.  
  416.         TOURNAMENT  :    Tournament selection (fast).
  417.  
  418.         INORDER        :    Inorder selection. The fittest individual is
  419.                 selected together with the rest in descending
  420.                 order of fitness.
  421.  
  422.         TEMPERATURE :    Boltzmann scaled selection. The selection
  423.                 pressure varies over time as determined by
  424.                 a 'heat' function. See also the EVL_Thermostat
  425.                 tag.
  426.  
  427.         UNIVERSAL   :    Universal stochastic selection (Improved
  428.                 variation on fitness proportionate selectsion).
  429.  
  430.     EVL_Stats (BOOL) - Generate statistics. Generating statistics will
  431.          increase processing time significantly compared to not doing it.
  432.          If statistics are enabled, the fitness function might be called
  433.          twice as many times. Once for every old individual for evaluation
  434.          and once for every new individual for generating statistics.
  435.          This is dependant on caching and previous state. When caching is
  436.          disabled, then the fitness function will always be called exactly
  437.          twice if generating statistics. Default is TRUE.
  438.  
  439.     EVL_PreMutate (BOOL) - Mutate old generation instead of new. This
  440.          will mutate the parent population before generating new
  441.          individuals. Note that this is done after evaluation so that
  442.          setting this tag to TRUE will mean that there is no nessecary
  443.          connection between good genes and a high fitness - only a
  444.          probability thereof (depending on the mutator function). This
  445.          emulates mutation occuring in mature individuals in nature.
  446.  
  447.     EVL_Newbies (int) - Number of new individuals to generate. The
  448.          individuals to replace will be randomly selected from the old
  449.          population. This could for example be used to keep the fitness
  450.          of a population down when co-evolving populations.
  451.  
  452.     EVL_Mensurator (double (*)(void *,void *,int)) - Pointer to a function
  453.          taking two pointers to individuals and their sizes and returning
  454.          the absolute value of the distance (dissimilarity measure) between
  455.          them. Default is to measure the Hamming distance between
  456.          individuals.
  457.  
  458.     EVL_Crowding (BOOL) - Use crowding replacement where each new
  459.          individual generated replaces the individual most like itself.
  460.          Note! This tag currently alters the meaning of the EVL_Elite
  461.          tag!
  462.  
  463.     EVL_InitDumped (BOOL) - If dumping individuals (see EVL_Dump above)
  464.          initialize them instead of replacing them with copies of the
  465.          fittest indiviuals.
  466.  
  467.     EVL_EraseBest (BOOL) - If generating new random individuals (see 
  468.          EVL_Newbies tag above) replace the fittest individuals instead
  469.          of random ones.
  470.  
  471.    RESULT
  472.     Pop    - A pointer to the population structure or NULL is something
  473.           went horribly wrong.
  474.  
  475.    NOTE
  476.     Note that Evolve always treats higher fitness values as better,
  477.     this means that you must take care to transform your fitness
  478.     values accordingly if needed before returning them.
  479.  
  480.    BUGS
  481.     None currently known but if there are any major bugs, this is probably
  482.     where they are.
  483.  
  484.    SEE ALSO
  485.  
  486.  
  487. GAP.lib/Flip                                                       GAP.lib/Flip
  488.  
  489.    NAME
  490.     Flip -- Flip a bit in a bitstring.
  491.  
  492.    SYNOPSIS
  493.     void Flip(void *,int);
  494.  
  495.     Flip(Ind,At);
  496.  
  497.    FUNCTION
  498.     Flips a bit in a bitstring. Bits are counted from lower addresses to
  499.     higher.
  500.  
  501.    INPUTS
  502.     Ind    - A pointer to the bitstring (individual).
  503.     At    - The bit-position to be flipped.
  504.  
  505.    RESULT
  506.     None.
  507.  
  508.    BUGS
  509.     None known.
  510.  
  511.    SEE ALSO
  512.     Testbit()
  513.  
  514.  
  515. GAP.lib/GaussRand                                             GAP.lib/GaussRand
  516.  
  517.    NAME
  518.     GaussRand -- Generate a gaussian pseudo-random number.
  519.  
  520.    SYNOPSIS
  521.     double GaussRand(double,double);
  522.  
  523.     Val = GaussRand(My,Sigma);
  524.  
  525.    FUNCTION
  526.     Generates a pseudo random number around My with a Gaussian
  527.     distribution.
  528.  
  529.    INPUTS
  530.     My    - Value around which to generate a random number.
  531.  
  532.     Sigma    - Standard deviation of the generated numbers.
  533.  
  534.    RESULT
  535.     Val    - A random number.
  536.  
  537.    BUGS
  538.     None known.
  539.  
  540.    SEE ALSO
  541.     Rnd(), InitRand(), InRand(), TossRand()
  542.  
  543.  
  544. GAP.lib/HammingDist                                         GAP.lib/HammingDist
  545.  
  546.    NAME
  547.     HammingDist -- Measure the Hamming distance between two bitstrings.
  548.  
  549.    SYNOPSIS
  550.     unsigned long int HammingDist(void *,void *,int);
  551.  
  552.     distance = HammingDist(Ind1,Ind2,Size);
  553.  
  554.    FUNCTION
  555.     Counts the number of differings bits in two bitstrings.
  556.  
  557.    INPUTS
  558.     Ind1    - Pointer to the first bitstring (Individual)
  559.     Ind2    - Pointer to the second bitstring (Individual)
  560.     Size    - Number of _BYTES_ in each bitstring.
  561.    
  562.    RESULT
  563.     The number of differing bits.
  564.  
  565.    BUGS
  566.     None known.
  567.  
  568.    SEE ALSO
  569.  
  570.  
  571. GAP.lib/InitRand                                               GAP.lib/InitRand
  572.  
  573.    NAME
  574.     InitRand -- Initialize pseudo-random number generator.
  575.  
  576.    SYNOPSIS
  577.     void InitRand(long);
  578.  
  579.     InitRand(seed);
  580.  
  581.    FUNCTION
  582.     Initializes the internal pseudo-random number generator. This function
  583.     should be called with an appropriate seed before any of the random
  584.     number functions are called. Note that Evolve() also uses the random
  585.     number functions. A default seed is supplied but it is not recommended
  586.     to leave this as it is since every run will then be identical.
  587.  
  588.    INPUTS
  589.     seed    - A seed value for the pseudo random number generator.
  590.  
  591.    RESULT
  592.     None.
  593.  
  594.    EXAMPLE
  595.     #include <stdlib.h> /* For definition of NULL */
  596.     #include <time.h>
  597.     #include <GAP.h>
  598.     ...
  599.     int main(void)
  600.     {
  601.     ...
  602.     InitRand(time(NULL));
  603.     ...
  604.     return(0);
  605.     }
  606.  
  607.    BUGS
  608.     A seed value of 0 will not work properly.
  609.  
  610.    SEE ALSO
  611.     Rnd(), InRand(), GaussRand(), TossRand()
  612.  
  613.  
  614. GAP.lib/InRand                                                   GAP.lib/InRand
  615.  
  616.    NAME
  617.     InRand -- Generate a bounded floating point pseudo-random number.
  618.  
  619.    SYNOPSIS
  620.     double InRand(double,double);
  621.  
  622.     Val = InRand(Lo,Hi);
  623.  
  624.    FUNCTION
  625.     Generates a pseudo random number between Lo and Hi. The resolution of
  626.     the generated number is in steps of (Hi-Lo)/2147483646.
  627.  
  628.    INPUTS
  629.     Lo    - Lower bound of the range in which to generate a random
  630.           number.
  631.     Hi    - Upper bound of the range in which to generate a random
  632.           number.
  633.  
  634.    RESULT
  635.     Val    - A random number in the range [Lo,Hi] (inclusive).
  636.  
  637.    BUGS
  638.     None known.
  639.  
  640.    SEE ALSO
  641.     Rnd(), InitRand(), GaussRand(), TossRand()
  642.  
  643.  
  644. GAP.lib/IRange                                                   GAP.lib/IRange
  645.  
  646.    NAME
  647.     IRange -- Map an integer onto a range.
  648.  
  649.    SYNOPSIS
  650.     double IRange(unsigned long int,double,double);
  651.  
  652.     v = IRange(Val,Lo,Hi);
  653.  
  654.    FUNCTION
  655.     Maps an unsigned long integer onto the range [Lo,Hi] (inclusive).
  656.  
  657.    INPUTS
  658.     Val - The value to map.
  659.     Lo  - Lower bound of the range.
  660.     Hi  - Higher bound of the range.
  661.  
  662.    RESULT
  663.     v   - A value in the range [Lo,Hi].
  664.  
  665.    BUGS
  666.     None known.
  667.  
  668.    SEE ALSO
  669.     InRand()
  670.  
  671.  
  672. GAP.lib/PopMember                                             GAP.lib/PopMember
  673.  
  674.    NAME
  675.     PopMember -- Get the n:th member of a population.
  676.  
  677.    SYNOPSIS
  678.     void *PopMember(struct Population *,int);
  679.  
  680.     Ind = PopMember(Pop,n);
  681.  
  682.    FUNCTION
  683.     Returns a pointer to the n:th individual in a population (counted from
  684.     zero). For a population with say 50 individuals, valid numbers would
  685.     range from 0 to 49.
  686.  
  687.    INPUTS
  688.     Pop    - A pointer to an population structure.
  689.     n    - The number of the individual to retrieve.
  690.  
  691.    RESULT
  692.     Ind    - A pointer to the n:th individual in the population.
  693.  
  694.    BUGS
  695.     None known.
  696.  
  697.    SEE ALSO
  698.     CreatePopulation()
  699.  
  700.  
  701. GAP.lib/Rnd                                                         GAP.lib/Rnd
  702.  
  703.    NAME
  704.     Rnd -- Generate a pseudo-random integer.
  705.  
  706.    SYNOPSIS
  707.     long int Rnd(long int);
  708.  
  709.     Val = Rnd(Hi);
  710.  
  711.    FUNCTION
  712.     Generates a pseudo-random integer between zero and one less than Hi.
  713.     The random number generator is cyclic and repeats after 2147483645
  714.     generated numbers.
  715.  
  716.    INPUTS
  717.     Hi    - Upper bound of random number.
  718.  
  719.    RESULT
  720.     Val    - An integer in the range [0,Hi[.
  721.  
  722.    BUGS
  723.     Hi can not be greater than 2147483646 (0x7ffffffe = 2^31-1).
  724.     This means that Rnd() only gives 31 random bits, not 32.
  725.     Also, the random number algorithm 'sucks' so to speak.
  726.  
  727.    SEE ALSO
  728.     InRand(), InitRand(), GaussRand(), TossRand()
  729.  
  730.  
  731. GAP.lib/Testbit                                                 GAP.lib/Testbit
  732.  
  733.    NAME
  734.     Testbit -- Test the status of an arbitrary bit in a bitstring.
  735.  
  736.    SYNOPSIS
  737.     int Testbit(void *,int);
  738.  
  739.     status = Testbit(Ind,At);
  740.  
  741.    FUNCTION
  742.     Tests the status of a bit in a bitstring. Bits are counted from lower
  743.     addresses to higher.
  744.  
  745.    INPUTS
  746.     Ind    - A pointer to the bitstring.
  747.     At    - The number of the bit to be tested.
  748.  
  749.    RESULT
  750.     0 if the bit is clear, non-zero otherwise.
  751.  
  752.    BUGS
  753.     None known.
  754.  
  755.    SEE ALSO
  756.     Flip()
  757.  
  758.  
  759. GAP.lib/TossRand                                               GAP.lib/TossRand
  760.  
  761.    NAME
  762.     TossRand -- Simulate the flip of a coin.
  763.  
  764.    SYNOPSIS
  765.     int TossRand(double);
  766.  
  767.     result = TossRand(Prob);
  768.  
  769.    FUNCTION
  770.     Returns 1 with a probability of Prob. A probability of 0.5 simulates
  771.     the toss of a fair coin.
  772.  
  773.    INPUTS
  774.     Prob    - The probability of the result being 1. Valid values are
  775.           in the range [0,1].
  776.  
  777.    RESULT
  778.     0 or 1.
  779.  
  780.    BUGS
  781.     None known.
  782.  
  783.    SEE ALSO
  784.     InRand(), InitRand(), GausRand(), Rnd()
  785.  
  786.